﻿#coding=utf-8
from django.db import models
from django.core.exceptions import ObjectDoesNotExist

# Create your models here.
#WAP论坛
SEX_TYPE = (
    ('male', 'male'),
    ('female', 'female'),
        
)
LEVEL = (
    ('玩机菜鸟', '玩机菜鸟'),
    ('玩机老鸟', '玩机老鸟'),
        
)


class BoardType(models.Model):

    board_type_name = models.CharField(maxlength=100,blank=False)

    datetime = models.DateTimeField(auto_now_add = True)
    
    
    def __str__(self):
        return self.board_type_name

    class Admin:
        pass



class Board(models.Model):

    board_name = models.CharField(maxlength=100,blank=False)

    board_rule = models.TextField(null=True,blank=True)

    topic_count = models.IntegerField(blank=True)

    board_type = models.ForeignKey(BoardType)

    #board_master = models.CharField(maxlength=100,blank=True)

    datetime = models.DateTimeField(auto_now_add = True)
    
    def __str__(self):
        return self.board_name

    class Admin:
        pass

class User(models.Model):

    user_name = models.CharField(maxlength=20,blank=False)

    password = models.CharField(maxlength=20,blank=False)

    uid = models.CharField(maxlength=500,blank=False)

    nick_name = models.CharField(maxlength=20,blank=True)

    sex = models.CharField(maxlength=20,choices=SEX_TYPE,blank=True)

    level = models.CharField(maxlength=100,choices=LEVEL,blank=True)

    money = models.IntegerField(blank=True)

    signed_name = models.CharField(maxlength=200,blank=True)

    phone = models.CharField(maxlength=100,blank=True)

    user_face = models.ImageField(upload_to='forum/sys_res/face_image/')

    topic_num_per_page = models.IntegerField(blank=True)

    #排序方式
    #post_num_per_page = models.IntegerField(blank=True)

    login_count = models.IntegerField(blank=True)

    datetime = models.DateTimeField(auto_now_add = True)

    board_master = models.ForeignKey(Board,null=True,blank=False)
    
    
    def __str__(self):
        return self.user_name

    class Admin:
        pass

class TopicCate(models.Model):

    cate_name = models.CharField(maxlength=100,blank=False)

    board = models.ForeignKey(Board)

        
    def __str__(self):
        return self.cate_name

    class Admin:
        pass

class Topic(models.Model):

    topic_name = models.CharField(maxlength=300,blank=False)

    topic_content = models.TextField(blank=False)

    author = models.ForeignKey(User)

    board = models.ForeignKey(Board)

    post_count = models.IntegerField(blank=True)

    read_count = models.IntegerField(blank=True)

    new_datetime = models.DateTimeField(auto_now_add = True)

    last_datetime = models.DateTimeField(auto_now = True)

    topic_cate = models.ForeignKey(TopicCate)

    isTop = models.BooleanField(null=False,blank=False)

    isFinest = models.BooleanField(null=False,blank=False)

    def __str__(self):
        return self.topic_name

    class Admin:
        pass

class Attachment(models.Model):

    topic = models.ForeignKey(Topic)

    attach_name = models.CharField(maxlength=200,blank=False)

    down_addr = models.FileField(upload_to='forum/user_res/attach/')

    down_count = models.IntegerField(blank=True)

    attach_size = models.IntegerField(blank=True)

    def __str__(self):
        return self.attach_name

    class Admin:
        pass

class Post(models.Model):

    topic = models.ForeignKey(Topic)

    post_content = models.TextField(blank=False)

    author = models.ForeignKey(User)

    datetime = models.DateTimeField(auto_now_add = True)

    
    def __str__(self):
        return self.post_content

    class Admin:
        pass

class PostAttachment(models.Model):

    post = models.ForeignKey(Post)

    attach_name = models.CharField(maxlength=200,blank=False)

    down_addr = models.FileField(upload_to='forum/user_res/attach/')

    down_count = models.IntegerField(blank=True)

    attach_size = models.IntegerField(blank=True)

    def __str__(self):
        return self.attach_name

    class Admin:
        pass

class Friend(models.Model):

    my = models.ForeignKey(User,related_name='my_user')

    friend = models.ForeignKey(User,related_name='friend_user')

    request_msg = models.CharField(maxlength=200,blank=True)

    isAgree = models.BooleanField(null=False,blank=False)

    datetime = models.DateTimeField(auto_now = True)

    def __str__(self):
        return self.my.user_name

    class Admin:
        pass

class Message(models.Model):

    sender = models.ForeignKey(User,related_name='sender_user')

    receiver = models.ForeignKey(User,related_name='receiver_user')

    title = models.CharField(maxlength=200,blank=False)

    content = models.TextField(blank=False)

    datetime = models.DateTimeField(auto_now_add = True)

    def __str__(self):
        return self.title + '(' + self.reveiver.user_name + ')'

    class Admin:
        pass
